package com.itheima.reggie.controller;

import com.itheima.reggie.common.OssTemplate;
import com.itheima.reggie.common.ResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Slf4j
public class FileController {

    @Autowired
    private OssTemplate ossTemplate;

    //上传文件
    @PostMapping("/common/upload")
    public ResultInfo uploadFile(MultipartFile file) throws Exception{ //1.接收文件对象
        //2.oss工具类上传文件
        String filePath = ossTemplate.upload(file.getOriginalFilename(), file.getInputStream());

        log.info("上传文件地址:" + filePath);
        //3.返回url地址
        return ResultInfo.success(filePath);

    }
}
